<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.openai-hk.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
// $headers[] = 'Authorization: Bearer hk-9ansk910000101128bcb0d667a98be8e6ddb8ad8527b3e80';
$headers[] = 'Authorization: Bearer hk-jxeeik10000101282a7c5304f4ba850251b60b381f5f6d2a';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = array(
    'max_tokens' => 1200,
    'model' => 'gpt-3.5-turbo',
    'temperature' => 0.8,
    'top_p' => 1,
    'presence_penalty' => 1,
    'messages' => array(
        // array(
        //     'role' => 'system',
        //     'content' => 'You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.'
        // ),
        array(
            'role' => 'user',
			'content' => '你是chatGPT多少？',
			// 'content' => '周树人和鲁迅是什么关系？',
			// 'content' => '我需要的商品信息是：耐酸碱防油水手套，型号：XL，计量单位：盒',
        )
    )
);

$data_string = json_encode($data);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

$result = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

// echo $result;

$arr = json_decode($result, true);
echo "<pre>";
print_r($arr);
echo "</pre>";
echo $arr['choices'][0]['message']['content'];



// Array
// (
//     [error] => Array
//         (
//             [message] => Insufficient points, please recharge 积分不足，请充值
//             [type] => openai_hk_error
//         )
// )